@{
    ViewBag.Title = "Bundestagswahl " + ViewBag.Bundestagswahl.Jahr;
}

@section scripts
{
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart", 'table'] });
        google.setOnLoadCallback(drawCharts);

        function drawCharts() {

            $.post('/Home/getPieChartData/?Jahr=@ViewBag.Bundestagswahl.Jahr', {},
                function(data) {
                    var tdata = new google.visualization.DataTable();

                    tdata.addColumn('string', 'Partei');
                    tdata.addColumn('number', 'Anzahl Sitze');
                    tdata.addColumn('string', 'Farbe');

                    for (var i = 0; i < data.length; i++) {
                        tdata.addRow([data[i].Parteiname, data[i].AnzahlPlaetze, data[i].Farbe]);
                    }

                    var options = {
                        title: "Sitzverteilung im Bundestag",
                        pieSliceText: "value"
                    };

                    tdata.sort([{ column: 1, desc: true }]);

                    var colors = [];
                    var numerOfRows = tdata.getNumberOfRows();
                    for (var j = 0; j < numerOfRows; j++) {
                        colors[j] = { color: tdata.getValue(j, 2) };
                    }

                    options["slices"] = colors;

                    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
                    chart.draw(tdata, options);

                    tdata.removeColumn(2);

                    var table = new google.visualization.Table(document.getElementById('table_ergebnisse_div'));
                    table.draw(tdata, { sortColumn: 1, sortAscending: false });
                });

            $.post('/Home/getPolitikerTableData/?Jahr=@ViewBag.Bundestagswahl.Jahr', {},
                function(data) {
                    var tdata = new google.visualization.DataTable();
                    tdata.addColumn('string', 'Vorname');
                    tdata.addColumn('string', 'Nachname');
                    tdata.addColumn('number', 'Jahrgang');
                    tdata.addColumn('string', 'Partei');

                    for (var i = 0; i < data.length; i++) {
                        tdata.addRow([data[i].Vorname, data[i].Nachname, data[i].Jahrgang, data[i].Parteiname]);
                    }

                    var options = {
                        sortColumn: 1
                    };

                    var table = new google.visualization.Table(document.getElementById('table_personen_div'));
                    table.draw(tdata, options);
                });

            $.post('/Home/getUeberhangmandate/?Jahr=@ViewBag.Bundestagswahl.Jahr', {},
                function(data) {
                    var tdata = new google.visualization.DataTable();
                    tdata.addColumn('string', 'Bundesland');
                    tdata.addColumn('string', 'Partei');
                    tdata.addColumn('number', 'Anzahl Überhangmandate');
                    for (var i = 0; i < data.length; i++) {
                        tdata.addRow([data[i].Bundeslandname, data[i].Parteiname, data[i].Ueberhangmandate]);
                    }

                    var options = {
                        sortColumn: 1
                    };

                    var table = new google.visualization.Table(document.getElementById('table_ueberhangmandate_div'));
                    table.draw(tdata, options);
                });

            $.post('/Home/getKnappsteAusgaenge/?Jahr=@ViewBag.Bundestagswahl.Jahr', {},
                function(data) {
                    var tdata = new google.visualization.DataTable();
                    tdata.addColumn('string', 'Vorname');
                    tdata.addColumn('string', 'Nachname');
                    tdata.addColumn('string', 'Wahlkreis');
                    tdata.addColumn('string', 'Partei');
                    tdata.addColumn('number', 'Differenz');
                    for (var i = 0; i < data.length; i++) {
                        tdata.addRow([data[i].Vorname, data[i].Nachname, data[i].Wahlkreisname, data[i].Parteiname, data[i].Differenz]);
                    }

                    var options = {
                        sortColumn: 1
                    };

                    var table = new google.visualization.Table(document.getElementById('table_knappste_ausgaenge_div'));
                    table.draw(tdata, options);
                });
        }
    </script>

}

@section featured
{
	<section class="featured">
		<div class="content-wrapper">
			<hgroup class="title">
				<h1>Bundestagswahl @ViewBag.Bundestagswahl.Jahr</h1>
				<h2>Ergebnisse auf Bundesebene</h2>
			</hgroup>
		</div>
	</section>
}

<div>
    <div>
        <a href="/Home/Index">Home</a> &gt; <b>Bundestagswahl @ViewBag.Bundestagswahl.Jahr</b>
    </div>

    <div>
        <table style="width: 100%; border-spacing: 3px;">
            <tr>
                @{
                    int i = 0;
                    foreach (var l in ViewBag.Laender)
                    {
                        <td>
                            <a href="/Home/Bundesland/@l.Id">@l.Name</a>
                        </td>
                        i++;
                        if (i > 3)
                        {
                            @:</tr><tr>
                            i = 0;
                        }
                    }
                }
            </tr>
        </table>
        <br/>
        <div id="chart_div" style="width: 900px; height: 500px;"></div>
        <div id="table_ergebnisse_div" style="width: 900px;"></div>
    </div>

    <div>
        <h3>Überhangmandate</h3><br/>
        <div id="table_ueberhangmandate_div" style="width: 900px;"></div>
    </div>
    
    <div>
        <h3>Mitglieder des Bundestages</h3><br/>
        <div id="table_personen_div" style="width: 900px;"></div>
    </div>
    
    <div>
        <h3>Knappste Ausgänge</h3><br/>
        <div id="table_knappste_ausgaenge_div" style="width: 900px;"></div>
    </div>
</div>
